package com.jeeboot.modules.job.controller;


import com.jeeboot.modules.job.entity.ScheduleJobEntity;
import com.jeeboot.modules.job.entity.ScheduleJobLogEntity;
import com.jeeboot.modules.job.service.ScheduleJobLogService;
import com.jeeboot.system.common.utils.PageUtils;
import com.jeeboot.system.common.utils.Query;
import com.jeeboot.system.common.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * Created by IntelliJ IDEA.
 * 作者: 李折训
 * 邮箱：370261528@qq.com
 * QQ群：571785017
 * 时间: 2017/11/29
 * 功能:定时任务日志
 */
@RestController
@RequestMapping("/sys/scheduleLog")
public class ScheduleJobLogController {
    @Autowired
    private ScheduleJobLogService scheduleJobLogService;

    /**
     * 定时任务日志列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:schedule:log")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        Page<ScheduleJobLogEntity> pageUtil = scheduleJobLogService.queryList(query, query.getPageable());
        return R.ok().put("page", pageUtil);
    }

    /**
     * 定时任务日志信息
     */
    @RequestMapping("/info/{logId}")
    public R info(@PathVariable("logId") Long logId) {
        Optional<ScheduleJobLogEntity> log = scheduleJobLogService.queryObject(logId);
        return R.ok().put("log", log.orElse(null));
    }
}
